<template>
<div style="width: 32%; border: green 1px solid">
		            <h2 style="text-align: center;">修改/添加</h2>
		            编号：<input type="text" v-model="tea.uid" readonly="readonly"/><br>
		            名字：<input type="text" v-model="tea.uname"/><br>
		            账号：<input type="text" v-model="tea.phone"><br>
		            密码：<input type="text" v-model="tea.pwd"><br>
		            图片：<input type="file" ref="img" /><br>
		            <div v-if="actidx!=0" style="width: 10vw;height: 10vw">
		                <img v-bind:src="`/adm/shows/${tea.pic}`" style="width: 100% ;height: 100%">
		            </div>
		            <button @click="addup()">添加/修改</button>
		        {{doadd}}
				</div>
</template>


<script>
	export default{
		data(){
			return{
				tea:{},
				token:"",
				doadd:""
			}
		},
		methods:{
			addup(){
				var that=this
				 //判断输入数据是否为空
				if(that.tea.uname==undefined||that.tea.phone==undefined||
					that.tea.pwd==undefined){
				    alert("添加不允许为空")
				    return;
				}
				let path=""
				if(that.tea.uid==0)path=this.$ip+"/api/adm/tea/add"
				if(that.tea.uid>0)path=this.$ip+"/api/adm/tea/update"
				console.log(path)
				var fd=new FormData()
				fd.append("uid",that.tea.uid)
				fd.append("uname",that.tea.uname)
				fd.append("phone",that.tea.phone)
				fd.append("pwd",that.tea.pwd)
				var filex=that.$refs.img.files[0]
				fd.append("mypic",filex)
				this.$axios.post(path,fd,{headers:{'Authorization':that.token}}).then(function(resp){
					that.doadd=resp.data.msg
					console.log(resp.data)
				})
			}
		},
		mounted() {
			var a=this.$route.query.id
			console.log(a)
			var that=this
			that.token=window.localStorage.getItem("token")
			if(a>0){
			this.$axios.get(this.$ip+"/api/adm/tea/findById/"+a,{headers:{'Authorization':that.token}}).then(function(resp){
				 	that.tea=resp.data.data
				 	console.log(resp.data.data)
				})
				}
			if(a==0)this.tea={uid:0,clz:{clzno:0}}
			
		}
	}
</script>

<style>
</style>
